//Hook ajax，ERP和易仓共用
(function(xhrobj) {
 var XHR = xhrobj.prototype;

 var send = XHR.send ;

 XHR.send = function(postData) {
     this.addEventListener('load', function() {
        var  myUrl = this.responseURL ? this.responseURL.toLowerCase() : this.responseURL;
         if(myUrl.includes("/fbaassess/datajson"))  { //捕获ERP测评数据接口的ajax
            if(this.responseType != 'blob' && this.responseText )  {
                try {
                    var text = this.responseText;  
                    console.log ('注入脚本已拦截到ajax返回数据');
                    // 发送消息到content.js
                    window.postMessage({type: "ERP_MESSAGE_TYPE_REVIEW", message:JSON.parse(text)})
                } catch (err)  {}
            }
         }
         if(myUrl.includes("/fbastock/datajson"))  { //捕获ERP备货数据接口的ajax
            if(this.responseType != 'blob' && this.responseText )  {
                try {
                    var text = this.responseText;  
                    console.log ('注入脚本已拦截到ajax返回数据');
                    // 发送消息到content.js
                    window.postMessage({type: "ERP_MESSAGE_TYPE_PREPAREGOODS", message:JSON.parse(text)})
                } catch (err)  {}
            }
         }
         if(myUrl.includes("/order/order-list/get-list-detail-list"))  { //捕获易仓订单列表数据接口的ajax
            if(this.responseType != 'blob' && this.responseText )  {
                try {
                    var text = this.responseText;  
                    console.log ('注入脚本已拦截到ajax返回数据');
                    // 发送消息到content.js
                    window.postMessage({type: "ECANG_ORDERS_MESSAGE_TYPE", message:JSON.parse(text)})
                } catch (err)  {}
            }
         }
         if(myUrl.includes("/statistics/report-center/inventory-export-report-list"))  { //捕获易仓报表中心数据接口的ajax
            if(this.responseType != 'blob' && this.responseText )  {
                try {
                    var text = this.responseText;  
                    console.log ('注入脚本已拦截到ajax返回数据');
                    // 发送消息到content.js
                    window.postMessage({type: "ECANG_INVENTORY_REPORT_MESSAGE_TYPE", message:JSON.parse(text)})
                } catch (err)  {}
            }
         }
     });
     return send.apply(this, arguments);
 };
})(XMLHttpRequest);